package com.cms.common.kit;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.cms.cache.CacheManager;

public class URLKit {

	public static boolean checkUrl(String requestUrl) {
		List<String> urls = (List<String>) CacheManager.get(Constant.CACHE_GLOBAL, Constant.CACHE_GLOBAL_NOT_FILTER_URL);
		for (String url : urls) {
			if(requestUrl.indexOf(url)!=-1)return false;
		}
		return true;
	}
	
	public static String getBaseUrl(HttpServletRequest request){
		String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";
		return basePath;
	}
	
	public static String getStaticUrl(){
		
		return null;
	}
	
	/**
	 * 获取去掉page参数的URL
	 * @param url
	 * @return
	 */
	public static String getPageUrl(String url){
		url = url.replaceAll("&?(page=[^&]*)", "");
		String param_chart="?";
		if(url.indexOf("?")>0)param_chart="&";
		if(!url.endsWith("?")&&!url.endsWith("&"))url+=param_chart;
		return url;
	}
	
	public static String getPageUrl(HttpServletRequest request){
		return getPageUrl(getCurrentUrl(request));
	}
	
	public static String getCurrentUrl(HttpServletRequest request){
		String url=request.getRequestURL().toString();
		String queryString=request.getQueryString();
		if(!StrKit.isBlank(queryString)){
			url+="?"+queryString;
		}
		return url;
	}
	
}
